import {
    FETCH_ME_SUCCESS,
    CREATE_USER_SUCCESS,
    LOGIN_SUCCESS
} from '../actions';

import { hashHistory } from 'react-router';

export default (state = { resources: {}}, action)=> {
    switch(action.type) {
        case LOGIN_SUCCESS:
            const newState = {...state, resources: action.response}
            setTimeout(() => hashHistory.push('/'), 0)
            return newState;
        case FETCH_ME_SUCCESS:
            return {...state, resources: action.response}
        case CREATE_USER_SUCCESS:
            const newstate = {
                ...state,
                resources: action.response
            }
            setTimeout(() => {
                hashHistory.push('/')
            }, 10);
            return newstate
        default:
            return state;
    }
}
